<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$types=array(
	'0'=>'新闻列表',
	'1'=>'手册列表',
	'2'=>'公告列表',
	'3'=>'更新列表'
);
$return=array();
if($_RQ['op']=='list'){
	$id=intval($_RQ['id']);
	$type=intval($_RQ['type']);
	$return['groups']=array();
	$return['list']=array();
	$site=core_setting('site');
	$operating=core_setting('operating');
	$return['site']=$site;
	$return['logo']=$site['logo'];
	$return['operating']=$operating;
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	if($id){
		$params=array(
			'group_id'=>$id,
			'status'=>1
		);
		$typetitle=pdo_get('core_article_group',array('id'=>$id));
		$typetitle=$typetitle['title'];
	}else{
		$params=array(
			'type'=>$type,
			'status'=>1
		);
		$typetitle=$types[$type];
	}
	$return['groups'] = pdo_getall('core_article_group',array('type'=>$type),array('id','title'),'','paixu asc');
	$return['list'] = pdo_getslice('core_article',$params,array($pindex,$psize),$total,array('id','title','content','createtime'),'','id desc');
	$return['type'] = $type;
	if($return['list']){
		foreach($return['list'] as &$item){
			$item['content'] = strip_tags(str_replace('&nbsp;','',$item['content']));;
			$item['desc'] = cfc('tools')->substr($item['content'],0,128);
			$item['createtime']=date('20y-m-d H:i:s',$item['createtime']);
			$item['url'] = manage_url('/home.news/detail/id='.$item['id']);
		}
	}
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$return['groupid']=$id ? $id : 0;
	$pindex = max(1, intval($_RQ['page']));
	$psize = 6;
	$return['hotlist'] = pdo_getslice('core_article',$params,array($pindex,$psize),$total,array('id','title','content','createtime'),'','readnum desc');
	$return['type'] = $type;
	if($return['hotlist']){
		foreach($return['hotlist'] as &$item){
			$item['content'] = strip_tags(str_replace('&nbsp;','',$item['content']));;
			$item['desc'] = cfc('tools')->substr($item['content'],0,128);
			$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
			$item['url'] = manage_url('/home.news/detail/id='.$item['id']);
		}
	}
	set_html('header','common/header-cms');
	set_html('title',$typetitle);
	exi($return);
}
if($_RQ['op']=='detail'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('找不到指定文章！','error');
	}
	//刷新阅读次数
	pdo_update('core_article',array('readnum +='=>1),array('id'=>$id));
	$return['groups']=array();
	$site=core_setting('site');
	$operating=core_setting('operating');
	$return['site']=$site;
	$return['operating']=$operating;
	$new= pdo_get('core_article',array('id'=>$id));
	$new['createtime']=date('Y-m-d H:i:s',$new['createtime']);
	$type=intval($new['type']);
	$return['groups'] = pdo_getall('core_article_group',array('type'=>$type),array('id','title'),'','paixu asc');
	$return['new'] = $new;
	$params=array('status'=>1);
	$pindex = max(1, intval($_RQ['page']));
	$psize = 6;
	$return['list'] = pdo_getslice('core_article',$params,array($pindex,$psize),$total,array('id','title','content','createtime'),'','id desc');
	if($return['list']){
		foreach($return['hotlist'] as &$item){
			$item['content'] = strip_tags(str_replace('&nbsp;','',$item['content']));;
			$item['desc'] = cfc('tools')->substr($item['content'],0,128);
			$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
			$item['url'] = manage_url('/home.news/detail/id='.$item['id']);
		}
	}
	$return['hotlist'] = pdo_getslice('core_article',$params,array($pindex,$psize),$total,array('id','title','content','createtime'),'','readnum desc');
	if($return['hotlist']){
		foreach($return['hotlist'] as &$item){
			$item['content'] = strip_tags(str_replace('&nbsp;','',$item['content']));;
			$item['desc'] = cfc('tools')->substr($item['content'],0,128);
			$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
			$item['url'] = manage_url('/home.news/detail/id='.$item['id']);
		}
	}
	$return['type'] = $type;
	set_html('header','common/header-cms');
	set_html('title',$new['title']);
	exi($return);
}
?>